using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace WF1.lab01
{
    public partial class frmRegister : Form
    {
        public frmRegister()
        {
            InitializeComponent();
            cbbEducation.SelectedIndex = 0;
        }

        private void cbxAgree_CheckedChanged(object sender, EventArgs e)
        {
            bttRegister.Visible = cbxAgree.Checked;
        }

        private void bttRegister_Click(object sender, EventArgs e)
        {
            Regex email  =  new Regex(@"^[A-z0-9]+([\.\-_]\w+)*@\w+([\.\-_]\w+)*(\.\w{2,4})+$");
            if (txtUsername.Text == "")
            {
                MessageBox.Show("Username can't be empty.","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                txtUsername.Focus();
            }
            else if (txtPassword.Text.Length < 6)
            {
                MessageBox.Show("Password length must greater than 6 characters.","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                txtPassword.Focus();
            }
            else if (txtPassword.Text != txtPassword2.Text)
            {
                MessageBox.Show("Password don't match.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPassword2.Focus();
            }
            else if (txtFullname.Text == "")
            {
                MessageBox.Show("Fullname can't be empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtFullname.Focus();
            }
            else if (email.IsMatch(txtEmail.Text) == false)
            {
                MessageBox.Show("Invalid email.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtEmail.Focus();
            }
            else if (mtxtPhone.MaskCompleted == false)
            {
                MessageBox.Show("Invalid phone.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                mtxtPhone.Focus();
            }
            else if (dtpBirthday.Value.Date > DateTime.Today.Date)
            {
                MessageBox.Show("Invalid Birthday.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                dtpBirthday.Focus();
            }
            else if (lbxLanguges.SelectedItems.Count == 0)
            {
                MessageBox.Show("You must choice languages.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                mtxtPhone.Focus();
            }
            else
            {
                frmResult f1 = new frmResult(txtUsername.Text, txtFullname.Text, rdoMale.Checked, txtEmail.Text, mtxtPhone.Text, dtpBirthday.Text, cbbEducation.Text, clbFavorites, lbxLanguges.SelectedItem.ToString());
                f1.ShowDialog();
                
            }
        }

        private void bttExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }          
                     
    }
}